package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.auxgroup.hr.front.service.hireperson.impl.HireEducatServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModZcgl;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dao.repository.PsCModZcglRepository;
import com.auxgroup.hr.front.service.modperson.ModZcglService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 资格证书流程信息service
 */
@Service("modZcglService")
public class ModZcglServiceImpl implements ModZcglService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCModZcglRepository PsCModZcglRepository;


	@Override
	public PsCModZcgl getModZcgl(PsCModPerPrimary modPerPrimary) {
		return PsCModZcglRepository.findOne(modPerPrimary);
	}


	@Override
	public PsCModZcgl save(PsCModZcgl ModZcgl,UserDTO user) {
		ModZcgl.setHrsRowAddOprid(user.getOprId());
		ModZcgl.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModZcgl.setHrsRowUpdOprid(user.getOprId());
		ModZcgl.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModZcgl,ignoreFields);
		return PsCModZcglRepository.save(ModZcgl);
	}


	@Override
	public Boolean delete(PsCModPerPrimary modPerPrimary) {
		try {
			PsCModZcglRepository.delete(modPerPrimary);
		} catch (Exception e) {
			logger.error("delete ModZcgl error: modPerPrimary={}",modPerPrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModZcgl> getAll(String cTransactionNbr,String emplid) {
		PsCModZcgl ModZcgl = new PsCModZcgl();
		ModZcgl.setEmplid(emplid);
		ModZcgl.setcTransactionNbr(cTransactionNbr);
		return PsCModZcglRepository.findAll(Example.of(ModZcgl));
	}


	
	
	
}
